<?php
	include "../public/commom/config.php";
	include "../public/commom/commom.php";
?>

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>商城</title>
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="public/index.css"/>
	</head>

	<body>
		<div id="header">
			<div style="height: 40px;" class="container">
				<div class="header-left">
					<a href="index.php">商城</a>
				</div>
				<div class="header-right">
					<a href="registered.php">注册</a>
					<a href="login.php">登录</a>
					<a href="personal.php">个人中心</a>
					<a href="javascript:;">查看订单</a>
					<a href="cart/index.php">购物车</a>
				</div>
			</div>
		</div>
		<div id="main">
			<div class="container">
				<div class="advert">
					<h6>广告</h6>
					<div class="advert-img">
						<?php
							$sql = "SELECT * FROM advert WHERE pos=0";
							
							$result = mysqli_query($conn, $sql);
							
							while($row = mysqli_fetch_array($result)) {
								echo "<a href='" . $row["rul"] . "'><img src='" . $imgPath . $row["img"] . "' width='100%'/></a>";
							}
						?>
					</div>
				</div>
				<div class="status">
					<a href="index.php">首页</a>
				</div>
				<div class="products">
					<?php
						$csql = "SELECT * FROM class";
						
						$cresult = mysqli_query($conn,$csql);
						
						while($row = mysqli_fetch_array($cresult)) {
							$class_id = $row["id"];
							echo "<h2>" . $row["name"] . "</h2>
								<a style='float: right;' href='more.php?class_id=" . $row["id"] . "' target='_blank'>更多>></a>
								<span style='float: right;margin-right: 10px;color: #ff6700;'>热销产品</span>";
							
							$ssql = "SELECT shop.* FROM shop LEFT JOIN brand ON (shop.brand_id = brand.id) LEFT JOIN class ON (brand.class_id = class.id) WHERE " . $row["id"] . " = class_id LIMIT 5";
									
							$sresult = mysqli_query($conn, $ssql);
							
							echo "<ul>";
							while($row = mysqli_fetch_array($sresult)) {
								echo "<li>
										<div class='products-img'><a href='details.php?class_id=" . $class_id . "&shop_id=" . $row["id"] . "'><img src='" . $imgPathThumb . $row["img"] . "'/></a></div>
										<h3>" . $row["name"] . "</h3>
										<p>" . $row["pice"] . "元</p>
										<span>库存：" . $row["inventory"] . "</span>
									</li>";
							}
							echo "</ul>";
						}
					?>
				</div>
				<div class="advert clearfix">
					<h6>广告</h6>
					<div class="advert-img">
						<?php
							$sql = "SELECT * FROM advert WHERE pos=1";
							
							$result = mysqli_query($conn, $sql);
							
							while($row = mysqli_fetch_array($result)) {
								echo "<a href='" . $row["rul"] . "'><img src='" . $imgPath . $row["img"] . "' width='100%'/></a>";
							}
							
							mysqli_close($conn);
						?>
					</div>
				</div>
			</div>
		</div>
		<div id="footer">
			
		</div>
	</body>

</html>